home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / attachCurveMidPoint.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.4 KB  |  106 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Jan 12, 1998
  22. //  Author:        mgr 
  23. //
  24. //  Description:
  25. //      The attachCurveMidPoint() procedure takes the selected two curves 
  26. //        (the end of curve1 and the start of curve2) and joins them at the 
  27. //        midpoint of the ends. If you don't want to attach the curves then 
  28. //        call this proc with $doAttach = 0.
  29. //
  30. //  Input Arguments:
  31. //      $doAttach - if 0 just move cvs, if 1 attach results
  32. //
  33. //  Return Value:
  34. //      String array.
  35. //
  36.  
  37. global proc string[] attachCurveMidPoint( int $doAttach )
  38. {
  39.     global int $gSelectNurbsCurvesBit;
  40.     string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`;
  41.  
  42.     string $resultCurve[];
  43.     int $numCurves = size($curvesList);
  44.     if ( $numCurves < 2 )
  45.     {
  46.         error("Need to select two curves.");
  47.         return $resultCurve;
  48.     }
  49.  
  50.     // make copies of the two curves
  51.     //
  52.     $curvesList = `duplicate`;
  53.  
  54.     // get the last cv on the first curve and the first cv on the second curve
  55.     //
  56.     int $degree = eval("getAttr " + $curvesList[0] + ".degree");
  57.     int $numSpans = eval("getAttr " + $curvesList[0] + ".spans");
  58.     int $numCVs = $degree + $numSpans;
  59.  
  60.     int $lastCV = $numCVs - 1;
  61.     float $cvCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`;
  62.     float $cvCurve2[] = `getAttr ($curvesList[1] + ".cp[0]")`;
  63.  
  64.     // this is the vector between the two cvs
  65.     //
  66.     float $vector[3];
  67.     $vector[0] = $cvCurve2[0] - $cvCurve1[0];
  68.     $vector[1] = $cvCurve2[1] - $cvCurve1[1];
  69.     $vector[2] = $cvCurve2[2] - $cvCurve1[2];
  70.  
  71.     // calculate the midpoint between the two cvs
  72.     //
  73.     float $cvNew[3];
  74.     $cvNew[0] = $cvCurve1[0] + ($vector[0] * 0.5);
  75.     $cvNew[1] = $cvCurve1[1] + ($vector[1] * 0.5);
  76.     $cvNew[2] = $cvCurve1[2] + ($vector[2] * 0.5);
  77.  
  78.     // move the end cv of curve1 and the start cv of curve2 to the midpoint
  79.     //
  80.      eval("select -r " + $curvesList[0] + ".cv[" + $lastCV + "] " + $curvesList[1] + ".cv[0]");
  81.     move -a $cvNew[0] $cvNew[1] $cvNew[2];
  82.  
  83.     // attach the 2 curves if required
  84.     //
  85.     if ( $doAttach == 1 )
  86.     {
  87.         // attach curve1 to curve2
  88.         //
  89.         string $attachedCurve[] = eval("attachCurve -ch 0 -rpo 1 -kmk 1 " + $curvesList[0] + " " + $curvesList[1]);
  90.  
  91.         // the second copied curve is no longer needed
  92.         //
  93.         delete $curvesList[1];
  94.  
  95.         $resultCurve[0] = $attachedCurve[0];
  96.     }
  97.     else
  98.     {
  99.         $resultCurve[0] = $curvesList[0];
  100.         $resultCurve[1] = $curvesList[1];
  101.     }
  102.  
  103.     select -r $resultCurve;
  104.     return $resultCurve;
  105. }
  106.